<template>
  <div class="icons">
    <swiper  :options="swiperOption">
       <swiper-slide v-for=" (page,index) of pages" :key=" index">
        <div class="icon" v-for= "item of page" :key ="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src = "item.imgUrl">
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
       </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  // data () {
  //   return {
  //     iconList: [{
  //       id: '001',
  //       imgUrl: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1528098048&di=17dcc8d31b83bd5cd1f00d647873cc66&imgtype=jpg&er=1&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimage%2Fc0%253Dshijue1%252C0%252C0%252C294%252C40%2Fsign%3D95985b5ea74bd11310c0bf7132c6ce7a%2F72f082025aafa40f16f671f0a164034f78f019ee.jpg',
  //       desc: '热门景点'
  //     }, {
  //       id: '002',
  //       imgUrl: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2995966449,2829320776&fm=11&gp=0.jpg',
  //       desc: '凯的小西装'
  //     }, {
  //       id: '003',
  //       imgUrl: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=737421447,187291794&fm=27&gp=0.jpg',
  //       desc: '赵子龙'
  //     }, {
  //       id: '004',
  //       imgUrl: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2888566907,378718255&fm=27&gp=0.jpg',
  //       desc: '貂蝉'
  //     }, {
  //       id: '005',
  //       imgUrl: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=277286299,2394512259&fm=27&gp=0.jpg',
  //       desc: '李白'
  //     }, {
  //       id: '006',
  //       imgUrl: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=306006078,1428760044&fm=27&gp=0.jpg',
  //       desc: '小乔'
  //     }, {
  //       id: '007',
  //       imgUrl: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=962230893,648422155&fm=27&gp=0.jpg',
  //       desc: '花木兰'
  //     }, {
  //       id: '008',
  //       imgUrl: 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1232839145,3479535919&fm=27&gp=0.jpg',
  //       desc: '张良'
  //     }, {
  //       id: '009',
  //       imgUrl: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2888566907,378718255&fm=27&gp=0.jpg',
  //       desc: '小貂蝉'
  //     }]
  //   }
  // },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    height: 0
    padding-bottom: 50%
  .icons
    margin-top: .1rem
    .icon
      position: relative
      overflow: hidden
      float: left
      width: 25%
      height: 0
      padding-bottom: 25%
      .icon-img
        position: absolute
        top:0
        left:0
        right:0
        bottom: .44rem
        background: #fff
        box-sizing:border-box
        padding: .1rem
        .icon-img-content
          display: block
          margin: 0 auto
          height:100%
          width: 100%
      .icon-desc
        position: absolute
        left: 0
        right: 0
        bottom: 0
        height: .44rem
        line-height: .44rem
        color: $darkTextColor
        text-align: center
        ellipsis()
</style>
